import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/util/ext_utils.dart';
import 'package:ls_work/viewmodel/patrol/offline_task_record_view_model.dart';

class OfflineTaskRecordPage extends BaseStatefulMvvmWidget {
  @override
  State<StatefulWidget> createState() => _OfflineTaskRecordState();
}

class _OfflineTaskRecordState extends BaseMvvmListState<
    OfflineTaskRecordViewModel, OfflineTaskRecordPage> {
  var _timeFormat = ['HH', ':', 'nn'];

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      appBar: AppBar(
        title: Text("本地巡防记录"),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  Widget buildLoadingContentView() {
    return Column(
      children: [
        super.buildLoadingContentView()!.setWeight(1),
        TextButton(
          onPressed: () {
            viewModel.startUpload();
          },
          child: Text(
            "一键上传",
            style: TextStyle(color: Colors.white),
          ),
          style: ButtonStyle(
              backgroundColor: WidgetStateProperty.all(Colors.blue),
              shape: WidgetStateProperty.all(RoundedRectangleBorder()),
              minimumSize:
                  WidgetStateProperty.all(Size(double.infinity, 48))),
        )
      ],
    );
  }

  @override
  Widget createItemWidget(int index) {
    var item = viewModel.listItems[index];
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        CommonText(item.pointName, fontWeight: FontWeight.bold, textSize: 17),
        Container(
          height: 10,
        ),
        CommonText(
            '巡防任务：${item.patrolName} (${item.startTime?.changeTime()}-${item.endTime?.changeTime()})',
            textSize: 15),
        Container(
          height: 10,
        ),
        CommonText('执行时间：${item.executeDate ?? ""}', textSize: 15)
      ],
    ).addToContainer(
        padding: EdgeInsets.symmetric(horizontal: 16, vertical: 10));
  }

  @override
  OfflineTaskRecordViewModel createViewModel() {
    return OfflineTaskRecordViewModel(context);
  }
}
